package com.usian.order.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.common.Result;
import com.usian.common.ResultCodeEnum;
import com.usian.entity.OrderDetails;
import com.usian.order.mapper.OrderDetailsMapper;
import com.usian.order.service.IOrderDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-01-15
 */
@Service
public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, OrderDetails> implements IOrderDetailsService {

    @Override
    public Result<OrderDetails> getOrderDetailsByOrderId(Integer orderId) {
        LambdaQueryWrapper<OrderDetails> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderDetails::getOrderId,orderId);
        OrderDetails orderDetails = getOne(wrapper);
        if (orderDetails == null){
            return Result.build(null, ResultCodeEnum.ORDER_DETAILS_NOT_EXIST);
        }
        return Result.build(orderDetails, ResultCodeEnum.SUCCESS);
    }

    @Override
    public List<OrderDetails> getOrderItemList(Integer orderId) {
        LambdaQueryWrapper<OrderDetails> eq = Wrappers.lambdaQuery(OrderDetails.class).eq(OrderDetails::getOrderId, orderId);
        return list(eq);
    }
}
